package org.example.controller;

import org.example.dao.ItemNotExistException;
import org.example.controller.pojo.JsonError;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionResolver {

    @ExceptionHandler(ItemNotExistException.class)
    public @ResponseBody JsonError handleException(RuntimeException exception) {
        return new JsonError(exception.getMessage());
    }

    @ExceptionHandler(ArithmeticException.class)
    public @ResponseBody JsonError handleArithmeticException(Exception exception) {
        return new JsonError(exception.getMessage());
    }
}
